package com.example.gokuplayalong.bases.tools;


import java.util.Timer;
import java.util.TimerTask;

public class CaptchaTimer {
    public static volatile int captchaTime = -1;
    public static volatile int getCaptchaSuccess = 1;
    public static volatile int verifyCaptchaSuccess = 0;

    public static volatile String captchaView = "";
    public static CaptchaTimer INSTANCE = null;
    private Timer timer = null;

    public static CaptchaTimer getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new CaptchaTimer();
        }
        return INSTANCE;
    }


    public void start() {
        if (timer != null) timer.cancel();
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (captchaTime > 0) {
                    captchaTime--;
                }
                else if (captchaTime == 0) {
                    captchaTime = -1;
                    cancel();
                }
            }
        }, 0, 1000);
    }
}
